﻿using A_txt;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DesktopShare
{
    public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();

            Class1_test buf = Deserialize2<Class1_test>();
            ;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            List<ModelManagement> _class = new List<ModelManagement>();
            ModelManagement buf;

            for (int i = 0; i < 10; i++)
            {
                buf = new ModelManagement();
                buf._classID = i;
                buf._className = i.ToString();
                buf._subClass = new subClass(i,null);
                _class.Add(buf);
            }


            ;
        }


        public class ModelManagement
        {
            public int _classID;
            public string _className;
            public subClass _subClass;
        }

        public class subClass
        {
            public int _classID;
            public DataTable _clasData;
            
            public subClass(int classID, DataTable clasData)
            {
                _classID = classID;
                _clasData = clasData;
            }
            public subClass()
            {
                _classID = 0;
                _clasData = null;
            }
        }


        public T Deserialize<T>()
        {

            using (FileStream fs = new FileStream("D:\\Person.adc", FileMode.Open))
            {
                BinaryFormatter binaryFormatter = new BinaryFormatter();
                return (T)binaryFormatter.Deserialize(fs);
            }
        }

        public T Deserialize2<T>()
        {

            using (FileStream fs = new FileStream("D:\\Person.adc", FileMode.Open))
            {
                IFormatter binaryFormatter = new BinaryFormatter();
                binaryFormatter.Binder = new UBinder();
                return (T)binaryFormatter.Deserialize(fs);
            }
        }

        public class UBinder : SerializationBinder
        {
            public override Type BindToType(string assemblyName, string typeName)
            {
                Assembly ass = Assembly.GetExecutingAssembly();
                return ass.GetType(typeName);
            }
        }


    }
}
